package com.sanjiahantang.youjiarole.module.me.scheme.views.impl;

import android.content.Intent;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.sanjiahantang.plugin.roundimage.RoundedImageView;
import com.sanjiahantang.uilibrary.adapter.listview.BaseAdapterHelper;
import com.sanjiahantang.uilibrary.adapter.listview.QuickAdapter;
import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.base.BaseMvpActivity;
import com.sanjiahantang.youjiarole.base.BaseView;
import com.sanjiahantang.youjiarole.module.me.scheme.beans.MeSchemeCaseListBean;
import com.sanjiahantang.youjiarole.module.me.scheme.presenters.MeSchemePresenter;
import com.sanjiahantang.youjiarole.module.me.scheme.views.MeSchemeView;
import com.squareup.picasso.Picasso;

import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;

import java.util.List;

/**
 * Created by zy on 2017/9/8.
 */

public class MeSchemeActivity extends BaseMvpActivity<MeSchemeView,MeSchemePresenter> implements MeSchemeView, View.OnClickListener, MeSchemeView.OnLoadListener {


    private View back;
    private MagicIndicator miTabs;
    private ListView listView;
    private String required_id;
    @Override
    public void showProgress() {
        super.showProgress($this);
    }

    @Override
    public MeSchemePresenter initPresenter() {
        return new MeSchemePresenter();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_scheme);

        TextView title = (TextView) findViewById(R.id.title);
        title.setText("我的方案");
        back = findViewById(R.id.fl_Left);
        back.setOnClickListener(this);

        miTabs = (MagicIndicator) findViewById(R.id.miTabs);
        listView = (ListView) findViewById(R.id.listView);
        listView.setSelector(R.color.transparent);
        required_id=getIntent().getStringExtra(KEY_ID);

    }

    @Override
    public void initData() {
      presenter.loadMySchemeCaseList($this,required_id);

        presenter.setOncliclisener(new BaseView.OnLoadListener() {
            @Override
            public void onLoad(final Object content) {

                Object[] param = (Object[]) content;
                switch ((int) param[0]) {
                    case MESCHEMELIST_ONE:
                        QuickAdapter<MeSchemeCaseListBean.Item> quickAdapter = new QuickAdapter<MeSchemeCaseListBean.Item>($this, R.layout.item_case_list) {
                            @Override
                            protected void convert(BaseAdapterHelper helper, final MeSchemeCaseListBean.Item item) {
                                helper.getView(R.id.llCollect).setVisibility(View.GONE);
                                helper.setVisible(R.id.llCollect, false);
                                helper.setText(R.id.tv_case_detail,item.getApartmentTypeName()+","+item.getLikeStyleName());
                                RoundedImageView roundedImageView=helper.getView(R.id.ivCaseMain);
                                Picasso.with($this).load(item.getUrl()).placeholder(R.drawable.i_match).error(R.drawable.i_match).into(roundedImageView);
                                helper.getView().setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        Intent intent = new Intent(context, MeSchemeCaseDetailActivity.class);
                                        intent.putExtra(KEY_ID,item.getPpId());
                                        intent.putExtra("totalstateid",item.getTotalStateId());
                                        intent.putExtra("isCommitOrder",item.getIsCommitOrder());
//                                        intent.putExtra("projectRoleId",item.getProjectRoleId());
//                                        intent.putExtra(KEY_VERSION,item.getVersion());
                                        startActivity(intent);
                                    }
                                });
                            }
                        };
                        quickAdapter.addAll((List<MeSchemeCaseListBean.Item>) param[1]);
                        listView.setAdapter(quickAdapter);
                        break;
                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.fl_Left:
                finish();
                break;

        }
    }

    @Override
    public void initTabs(CommonNavigatorAdapter adapter) {

    }

    @Override
    public void switchPages(int index) {
    }

    @Override
    public void initList(QuickAdapter adapter) {
    }
}
